class Button extends PIXI.Container {
	constructor(text, size, lineStyle) {
		super();

		this.text = text;
		this.size = size;
		this.lineStyle = lineStyle || 0x284850;

		// 添加信息栏背景
		this.normal();
	}

	normal() {
		for(var i = 0; i < this.children.length; i++) {
			this.removeChild(this.children[i]);
			i--;
		}

		const infoBg = new PIXI.Graphics();
		infoBg.beginFill(0xA0C0B0, 1);
		infoBg.lineStyle({ color: this.lineStyle, width: 1, alignment: 0 });
		infoBg.drawRoundedRect(1,1,this.size.width,this.size.height,6);
		infoBg.lineStyle({ color: 0x181818, width: 0, alignment: 0 });
		infoBg.beginFill(0xC0F0E8, 1);
		infoBg.drawRoundedRect(1,1,this.size.width-2,this.size.height-2,6);
		infoBg.beginFill(0xFCFCFC, 1);
		infoBg.drawRoundedRect(2,2,this.size.width-4,this.size.height-4,6);
		infoBg.endFill();
		this.addChild(infoBg);

		// 绘制文字
		const textStyle = new PIXI.TextStyle({
			fontFamily: 'Microsoft YaHei',
			fontSize: 14,
			fontWeight: 'bold',
			fill: ['#181818'],
			stroke: '#000000',
			strokeThickness: 0
		});

		const literal = new PIXI.Text(this.text, textStyle);
		const literalSize = PIXI.TextMetrics.measureText(this.text, textStyle);
		literal.x = (this.size.width - literalSize.width) / 2;
		literal.y = (this.size.height - literalSize.height) / 2;
		literal.resolution = 2;
		this.addChild(literal);

		setTimeout(() => {
			this.pressed();
		}, 300);
	}

	pressed() {
		for(var i = 0; i < this.children.length; i++) {
			this.removeChild(this.children[i]);
			i--;
		}

		const infoBg = new PIXI.Graphics();
		infoBg.beginFill(0xA0C0B0, 1);
		infoBg.lineStyle({ color: this.lineStyle, width: 1, alignment: 0 });
		infoBg.drawRoundedRect(1,1,this.size.width,this.size.height,6);
		infoBg.lineStyle({ color: 0x181818, width: 0, alignment: 0 });
		infoBg.beginFill(0xC0F0E8, 1);
		infoBg.drawRoundedRect(1,1,this.size.width-2,this.size.height-2,6);
		infoBg.beginFill(0xFCFCFC, 1);
		infoBg.drawRoundedRect(3,3,this.size.width-6,this.size.height-6,6);
		infoBg.endFill();
		this.addChild(infoBg);

		// 绘制文字
		const textStyle = new PIXI.TextStyle({
			fontFamily: 'Microsoft YaHei',
			fontSize: 14,
			fontWeight: 'bold',
			fill: ['#181818'],
			stroke: '#000000',
			strokeThickness: 0
		});

		const literal = new PIXI.Text(this.text, textStyle);
		const literalSize = PIXI.TextMetrics.measureText(this.text, textStyle);
		literal.x = (this.size.width - literalSize.width + 1) / 2;
		literal.y = (this.size.height - literalSize.height + 1) / 2;
		literal.resolution = 2;
		this.addChild(literal);

		setTimeout(() => {
			this.normal();
		}, 300);
	}
}